home *** CD-ROM | disk | FTP | other *** search
/ Champak 29 / Volume 29 - JOGO DISK .iso / Games / jungle_adventure.swf / scripts / __Packages / RollingObject.as < prev    next >
Text File  |  2006-11-29  |  4KB  |  106 lines

  1. class RollingObject extends SSObject
  2. {
  3.    var classID = SSGlobal.CLSID_MOBILEOBJECT;
  4.    var collisionMask = SSGlobal.CLSID_SHAPE | SSGlobal.CLSID_MAINCHAR;
  5.    var assetID = "Log";
  6.    var healthValue = -0.1;
  7.    var minVelocity = 0;
  8.    var gravity = SSGlobal.GRAVITY;
  9.    var contact = false;
  10.    var collision = false;
  11.    var editor_isItem = true;
  12.    var editor_name = "RollingObject";
  13.    var editor_args_names = ["healthValue"];
  14.    var editor_args_values = [RollingObject.prototype.healthValue];
  15.    var editor_args_types = ["number"];
  16.    var editor_args_options = [[-1,1,0.01]];
  17.    var editor_args_descriptions = [""];
  18.    var editor_args_mode = [0];
  19.    var editor_args_component = ["NumericStepper"];
  20.    function RollingObject()
  21.    {
  22.       super();
  23.    }
  24.    function onAddToWorld()
  25.    {
  26.       this.originX = this.x;
  27.       this.originY = this.y;
  28.    }
  29.    function onAddToScene()
  30.    {
  31.       this.velocity.x = this.velocity.y = 0;
  32.       this.getUpdates();
  33.    }
  34.    function onRemoveFromScene()
  35.    {
  36.       this.cancelUpdates();
  37.       this.moveTo(this.originX,this.originY,0);
  38.       this.contact = null;
  39.    }
  40.    function update(elapsed)
  41.    {
  42.       if(this.contact)
  43.       {
  44.       }
  45.       this.velocity.y += this.gravity * elapsed;
  46.       this.collision = false;
  47.       this.checkCollisions(elapsed);
  48.       this.moveBy(this.velocity.x * elapsed,this.velocity.y * elapsed,0);
  49.    }
  50.    function setContact(edge)
  51.    {
  52.       this.contact = edge;
  53.    }
  54.    function checkCollision(obj)
  55.    {
  56.       var _loc2_ = undefined;
  57.       switch(obj.classID & 4294901760)
  58.       {
  59.          case SSGlobal.CLSID_SHAPE:
  60.             if(!this.contact && (_loc2_ = SSCollision.sweepSphereToStaticShape(this,obj)))
  61.             {
  62.                var _loc11_ = this.velocity.__get__length();
  63.                var _loc8_ = _loc2_.normal.x * this.velocity.x + _loc2_.normal.y * this.velocity.y;
  64.                var _loc6_ = _loc8_ * _loc2_.normal.x;
  65.                var _loc5_ = _loc8_ * _loc2_.normal.y;
  66.                var _loc10_ = this.velocity.x - _loc6_;
  67.                var _loc9_ = this.velocity.y - _loc5_;
  68.                var _loc3_ = undefined;
  69.                if(!(_loc3_ = _loc2_.edge.attributes.bounciness))
  70.                {
  71.                   _loc3_ = 0;
  72.                }
  73.                this.velocity.x = _loc10_ - _loc3_ * _loc6_;
  74.                this.velocity.y = _loc9_ - _loc3_ * _loc5_;
  75.                var _loc7_ = this.motionTime - _loc2_.time;
  76.                this.moveTo(_loc2_.point.x + _loc2_.edge.normal.x * 1 + this.velocity.x * _loc7_,_loc2_.point.y + _loc2_.edge.normal.y * 1 + this.velocity.y * _loc7_,0);
  77.                this.collision = true;
  78.             }
  79.             break;
  80.          case SSGlobal.CLSID_MAINCHAR:
  81.             if(SSCollision.sweepSphereToSphere(this,obj,true))
  82.             {
  83.                return this.onCollision(obj);
  84.             }
  85.             break;
  86.       }
  87.    }
  88.    function onCollision(obj)
  89.    {
  90.       if(!this.inScene)
  91.       {
  92.          return undefined;
  93.       }
  94.       if(obj.active && (obj.classID & 4294901760) == SSGlobal.CLSID_MAINCHAR)
  95.       {
  96.          obj.shiftHealth(this.healthValue,this);
  97.          var _loc2_ = new SSParticle(this.assetID,4,new Vector(obj.velocity.x * 0.5,this.velocity.y * 0.5,-300),45,SSGlobal.GRAVITY);
  98.          _loc2_.alpha = false;
  99.          _loc2_.x = this.x;
  100.          _loc2_.y = this.y;
  101.          this.world.addObject(_loc2_);
  102.          this.removeFromScene();
  103.       }
  104.    }
  105. }
  106.